﻿

<style>
    .demo-reg-container {
        width: 320px;
        margin: 21px auto 0;
    }

    .demo-reg-other .layui-icon {
        position: relative;
        display: inline-block;
        margin: 0 2px;
        top: 2px;
        font-size: 26px;
    }
</style>
<form class="layui-form">
    <div class="demo-reg-container">
        <input id="id" name="id" type="hidden">
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <div class="layui-input-prefix">
                    <i class="layui-icon layui-icon-username"></i>
                </div>
                <input id="name" name="name" lay-verify="required" placeholder="用户名" lay-reqtext="请填写用户名" autocomplete="off" class="layui-input" lay-affix="clear">
            </div>
        </div>
        @*<div class="layui-form-item">
            <div class="layui-input-wrap">
                <div class="layui-input-prefix">
                    <i class="layui-icon layui-icon-password"></i>
                </div>
                <input type="password" asp-for="Password" value="" lay-verify="required" placeholder="密码" lay-reqtext="请填写密码" autocomplete="off" class="layui-input" id="reg-password" lay-affix="eye">
            </div>
        </div>*@
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <div class="layui-input-prefix">
                    <i class="layui-icon layui-icon-username"></i>
                </div>
                <input id="nickName" name="nickName" lay-verify="required" placeholder="昵称" lay-reqtext="请填写昵称" autocomplete="off" class="layui-input" lay-affix="clear">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <div class="layui-input-prefix">
                    <i class="layui-icon layui-icon-username"></i>
                </div>
                <input id="email" name="email" lay-verify="required" placeholder="邮箱" autocomplete="off" class="layui-input" lay-affix="clear">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-row">
                <div class="layui-col-xs7">
                    <div class="layui-input-wrap">
                        <div class="layui-input-prefix">
                            <i class="layui-icon layui-icon-cellphone"></i>
                        </div>
                        <input id="phone" name="phone" lay-verify="phone" placeholder="手机号" lay-reqtext="请填写手机号" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <button id="modify" class="layui-btn layui-btn-fluid" lay-submit lay-filter="modify">修改</button>
        </div>
    </div>
</form>

<script>

    $(document).ready(function () {
        $.post('/User/UserInfo',  function (res) {
            if (true == res.success)
                var model = res.data;
                console.log( model);
            $("#id").val(model.id);
                $("#name").val(model.name);
                $("#nickName").val(model.nickName);
                $("#email").val(model.email);
                $("#phone").val(model.phone);
        });
    });
    layui.use(function () {
        var $ = layui.$;
        var form = layui.form;
        var layer = layui.layer;
        var util = layui.util;
        layui.use('form', function () {
            var form = layui.form;
            var layer = layui.layer;
            var $ = layui.jquery
            //layui表单提交方法
            form.on('submit(modify)', function (data) {
                var user = data.field; 
                ////layer.alert(JSON.stringify(field), {
                ////    title: '当前填写的字段值'
                ////});
                //layer.alert(user.id,3000);
                //return false;
                $.post('/User/Modify', user, function (res) {
                    console.log(res);
                    if (true == res.success)
                        layer.msg(res.message, { icon: 1 });
                    else {//失败则弹出失败提示
                        layer.msg(res.message, { icon: 5 });
                    }
                });
                return false;
            });
        });

    });
</script>